#cd .. #Move to parent directory (should have Total_Mayhem.csproj) 
$folder = ($myInvocation.InvocationName).Remove($myInvocation.InvocationName.Length-27) #Should be folder with csproj file
echo "Changing folder to: $folder"
cd $folder

nuget pack Total_Mayhem.csproj -build -Prop Configuration=Release -OutputDirectory NugetPackage -verbose -Exclude 'Loya*;nircmd\*.*'
if ($LASTEXITCODE -eq 0){
    echo "`nRenaming .nupkg file to .mayhem"
    foreach ($pkg in @(gci NugetPackage\*.nupkg))
    {
        $newfilename = "{0}\{1}.mayhem" -f $pkg.DirectoryName,$pkg.BaseName
        #if(test-path $newfilename){
        #    echo "File $($pkg.BaseName).mayhem already exists... deleting old file."
        #    del $newfilename -Force
        #}
        
        #$pkg.MoveTo($newfilename)
    	Copy-Item $pkg.FullName $newfilename -Force
    }
} else {
  echo "Failed creating Nuget package for Total_Mayhem!"
}

read-host
